package com.rxkj.controller;

import com.rxkj.entity.rainwater.ImageSt;
import com.rxkj.entity.rainwater.RainSt;
import com.rxkj.entity.rainwater.WaterAndRainVO;
import com.rxkj.entity.rainwater.WaterSt;
import com.rxkj.service.WaterAndRainService;
import com.rxkj.utils.PageData;
import com.rxkj.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 水雨情数据API
 *
 * @author alex
 * @date 2022-10-30 20:10:42
 */
@Api(tags = "水雨情监测")
@RestController
@RequestMapping(value = "/waterandrain-api")
public class WaterAndRainController {

    private static Logger logger = LoggerFactory.getLogger(WaterAndRainController.class);

    @Autowired
    private WaterAndRainService waterAndRainService;

    /**
     * 水雨情概览
     *
     * @param currentPage 当前页面
     * @param pageSize    页面大小
     * @param stnm        测站名称
     * @return {@link ResponseResult}<{@link List}<{@link WaterAndRainVO}>>
     */
    @ApiOperation("站点水雨情数据")
    @GetMapping("/getWaterAndRainOverview")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", required = true, value = "当前页码"),
            @ApiImplicitParam(name = "pageSize", required = true, value = "每页条数"),
            @ApiImplicitParam(name = "stnm", required = false, value = "测站名称")
    })
    //@RoleLevel(2)
    public ResponseResult<List<WaterAndRainVO>> getWaterAndRainOverview(@RequestParam("currentPage") int currentPage,
                                                  @RequestParam("pageSize") int pageSize,
                                                  @RequestParam(value = "stnm", required = false) String stnm){
        PageData<WaterAndRainVO> qe = waterAndRainService.getWaterAndRainOverview(currentPage, pageSize, stnm);
        return qe.getRows().size() > 0? (ResponseResult<List<WaterAndRainVO>>) ResponseResult.success("查询成功...", qe) : (ResponseResult<List<WaterAndRainVO>>) ResponseResult.success("未查询到数据...", qe);
    }

    /**
     * 雨量历史时段数据
     *
     * @param currentPage 当前页面
     * @param pageSize    页面大小
     * @param termsn      termsn
     * @param startTime   开始时间
     * @param endTime     结束时间
     * @return {@link ResponseResult}<{@link List}<{@link RainSt}>>
     */
    @ApiOperation("雨量历史时段数据")
    @GetMapping("/getRainsByTermsn")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", required = true, value = "当前页码"),
            @ApiImplicitParam(name = "pageSize", required = true, value = "每页条数"),
            @ApiImplicitParam(name = "termsn", required = true, value = "测站编码termsn"),
            @ApiImplicitParam(name = "startTime", required = false, value = "开始时间"),
            @ApiImplicitParam(name = "endTime", required = false, value = "结束时间"),
    })
    //@RoleLevel(2)
    public ResponseResult<List<RainSt>> getRainsByTermsn(@RequestParam("currentPage") int currentPage,
                                                         @RequestParam("pageSize") int pageSize,
                                                         @RequestParam("termsn") String termsn,
                                                         @RequestParam(value = "startTime", required = false) String startTime,
                                                         @RequestParam(value = "endTime", required = false) String endTime){
        PageData<RainSt> qe = waterAndRainService.getRainsByTermsn(currentPage, pageSize, termsn, startTime, endTime);
        return qe.getRows().size() > 0? (ResponseResult<List<RainSt>>) ResponseResult.success("查询成功...", qe) : (ResponseResult<List<RainSt>>) ResponseResult.success("未查询到数据...", qe);
    }


    @ApiOperation("雨量数据按类型无分页")
    @GetMapping("/getRainData")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "timetype", required = true, value = "1,5min;2,1h;3,1day"),
            @ApiImplicitParam(name = "startTime", required = true, value = "开始时间"),
            @ApiImplicitParam(name = "endTime", required = true, value = "结束时间"),
            @ApiImplicitParam(name = "termsn", required = true, value = "测站编码termsn")
    })
    //@RoleLevel(2)
    public ResponseResult<RainSt> getRainData(@RequestParam(value = "timetype", required = true, defaultValue = "1") int timetype,
                                      @RequestParam(value = "startTime", required = true) String startTime,
                                      @RequestParam(value = "endTime", required = true) String endTime,
                                      @RequestParam(value = "termsn", required = true) String termsn){
        List<RainSt> qe = waterAndRainService.getRainData(timetype, startTime, endTime, termsn);
        return qe.size() > 0? (ResponseResult<RainSt>) ResponseResult.success("查询成功...", qe) : (ResponseResult<RainSt>) ResponseResult.success("未查询到数据...", qe);
    }

    /**
     * 水位历史时段数据
     *
     * @param currentPage 当前页面
     * @param pageSize    页面大小
     * @param termsn      termsn
     * @param startTime   开始时间
     * @param endTime     结束时间
     * @return {@link ResponseResult}<{@link List}<{@link WaterSt}>>
     */
    @ApiOperation("水位历史时段数据")
    @GetMapping("/getWatersByTermsn")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", required = true, value = "当前页码"),
            @ApiImplicitParam(name = "pageSize", required = true, value = "每页条数"),
            @ApiImplicitParam(name = "termsn", required = true, value = "测站编码termsn"),
            @ApiImplicitParam(name = "startTime", required = false, value = "开始时间"),
            @ApiImplicitParam(name = "endTime", required = false, value = "结束时间"),
    })
    //@RoleLevel(2)
    public ResponseResult<List<WaterSt>> getWatersByTermsn(@RequestParam("currentPage") int currentPage,
                                                           @RequestParam("pageSize") int pageSize,
                                                           @RequestParam("termsn") String termsn,
                                                           @RequestParam(value = "startTime", required = false) String startTime,
                                                           @RequestParam(value = "endTime", required = false) String endTime){
        PageData<WaterSt> qe = waterAndRainService.getWatersByTermsn(currentPage, pageSize, termsn, startTime, endTime);
        return qe.getRows().size() > 0? (ResponseResult<List<WaterSt>>) ResponseResult.success("查询成功...", qe) : (ResponseResult<List<WaterSt>>) ResponseResult.success("未查询到数据...", qe);
    }

    @ApiOperation("水位数据按类型无分页")
    @GetMapping("/getWaterData")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "termsn", required = true, value = "测站编码termsn"),
            @ApiImplicitParam(name = "startTime", required = false, value = "开始时间"),
            @ApiImplicitParam(name = "endTime", required = false, value = "结束时间"),
    })
    //@RoleLevel(2)
    public ResponseResult<WaterSt> getWaterData(@RequestParam("termsn") String termsn,
                                                @RequestParam(value = "startTime", required = false) String startTime,
                                                @RequestParam(value = "endTime", required = false) String endTime){
        List<WaterSt> qe = waterAndRainService.getWaterData(termsn, startTime, endTime);
        return qe.size() > 0? (ResponseResult<WaterSt>) ResponseResult.success("查询成功...", qe) : (ResponseResult<WaterSt>) ResponseResult.success("未查询到数据...", qe);
    }

    /**
     * 图片历史时段数据
     *
     * @param termsn      termsn
     * @param startTime   开始时间
     * @param endTime     结束时间
     * @return {@link ResponseResult}<{@link List}<{@link ImageSt}>>
     */
    @ApiOperation("图片历史时段数据")
    @GetMapping("/getImagesByTermsn")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "termsn", required = true, value = "测站编码termsn"),
            @ApiImplicitParam(name = "startTime", required = false, value = "开始时间"),
            @ApiImplicitParam(name = "endTime", required = false, value = "结束时间")
    })
    //@RoleLevel(2)
    public ResponseResult<List<ImageSt>> getImagesByTermsn(@RequestParam("termsn") String termsn,
                                                           @RequestParam(value = "startTime", required = false) String startTime,
                                                           @RequestParam(value = "endTime", required = false) String endTime){
        List<ImageSt> qe = waterAndRainService.getImagesByTermsn(termsn, startTime, endTime);
        return qe.size() > 0? (ResponseResult<List<ImageSt>>) ResponseResult.success("查询成功...", qe) : (ResponseResult<List<ImageSt>>) ResponseResult.success("未查询到数据...", qe);
    }

}
